//
//  PublishViewController.m
//  Four_Fit_New
//
//  Created by lanou on 16/7/22.
//  Copyright © 2016年 xmaz. All rights reserved.
//

#import "PublishViewController.h"
#import "CircleSpreadTransition.h"
#import "UIViewController+XHPhoto.h"

@interface PublishViewController ()<UIViewControllerTransitioningDelegate>
@property (weak, nonatomic) IBOutlet UITextField *titleTF;
@property (weak, nonatomic) IBOutlet UITextView *contentTF;
@property (weak, nonatomic) IBOutlet UIButton *publishBtn;
/** 存放imageView */
@property (nonatomic, strong) NSMutableArray *ImageViewArray;
/** 记录加几张图片 */
@property (nonatomic, assign) NSInteger index;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *publishBtnX;

@end

@implementation PublishViewController

- (NSMutableArray *)ImageViewArray {
    if (!_ImageViewArray) {
        _ImageViewArray = [NSMutableArray array];
    }
    return _ImageViewArray;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.transitioningDelegate = self;
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
   

    for (int i = 0; i < 3; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(110 * i + 10, 250, 100, 100)];
        [self.ImageViewArray addObject:imageView];
    }
    
}
- (IBAction)dismiss:(id)sender {
    
    [self.view endEditing:YES];
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    if ([self.delegate respondsToSelector:@selector(pubishViewController:)]) {
        [self.delegate pubishViewController:self];
    }
}

- (IBAction)publish:(id)sender {

    UIImageView *imageView = self.ImageViewArray[self.index];
    [self showCanEdit:YES photo:^(UIImage *photo) {
        
        imageView.image = photo;
        [self.view addSubview:imageView];
        
        for (NSInteger i = self.index; i < self.index; i++) {
            self.publishBtnX.constant = 110 * (i + 1) + 10;
        }
        
        self.index++;
    }];
    
    if (self.index == 3) {
        self.publishBtn.hidden = YES;
    }
}



- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return [CircleSpreadTransition transitionWithTransitionType:CircleSpreadTransitionTypePresent];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    return [CircleSpreadTransition transitionWithTransitionType:CircleSpreadTransitionTypeDismiss];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
